package com.app.admin.config;

import com.alibaba.fastjson.annotation.JSONField;
import com.app.core.redis.CommonRedisKey;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author qiangt
 * @since 2022/12/9 12:13
 */
@ConfigurationProperties(prefix = "cyt.lock")
@Component
@Setter
@Getter
public class LockProperties {

    private Map<String, Config> config;

    @Setter
    @Getter
    public static class Config {

        /**
         * 名称
         */
        private String lockKey = CommonRedisKey.RedissonLockKey.key(Config.class.getName());
        /**
         * 等待时间（单位：毫秒），默认值为6秒
         */
        private long waitTime = 6000;
        /**
         * 租赁时间（单位：毫秒），默认值为12秒
         */
        private long leaseTime = 12000;

        @JsonIgnore
        @JSONField(deserialize = false, serialize = false)
        public String getLockKey() {
            return CommonRedisKey.RedissonLockKey.key(this.lockKey);
        }
    }

}


